#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10,W = 1e6 + 0;
inline int read()
{
    int f = 1,x = 0;
    char ch = getchar();
    while(ch > '9' || ch < '0')
    {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0',ch = getchar();
    return f * x;
}

inline void write(int x)
{
    if(x < 0) putchar('-'),x = -x;
    if(x > 9) write(x / 10);
    putchar(x % 10 + '0');
    return;
}

struct node
{
    int d,v,a;
    bool operator <(const node &h) const
    {
        return d < h.d;
    }
}car[N];
int T,n,m,L,V;
int p[N];
int ans1[N],ans2[N];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    T = read();
    int hjy = 0;
    while(T--)
    {
        hjy += 1;
        n = read();
        m = read();
        L = read();
        V = read();
        for(int i = 1;i <= n;i++)
        {
            car[i].d = read();
            car[i].v = read();
            car[i].a = read();
        }
        bool flag = 1;
        for(int i = 1;i <= n;i++)
        {
            if(car[i].a != 0) flag = 0;
        }
        for(int i = 1;i <= m;i++)
            p[i] = read();
        if(flag == 1)
        {
            sort(p + 1,p + m + 1);
            sort(car + 1,car + n + 1);
            int minp = p[1];
            int res1 = 0,res2 = 0;
            for(int i = 1;i <= n;i++)
            {
                if(car[i].v > V) res1++;
            }
            if(res1 == 0)
            {
                ans1[hjy] = res1;
                ans2[hjy] = 0;
            }
            else
            {
                ans1[hjy] = res1;
                ans2[hjy] = 1;
            }
        }
        else
        {
            ans1[hjy] = 3;
            ans2[hjy] = 3;
        }
    }
    for(int i = 1;i <= hjy;i++)
    {
        write(ans1[i]);
        putchar(' ');
        write(ans2[i]);
        putchar('\n');
    }
    return 0;
}
